# -*-coding:utf-8-*-

import ConfigParser

conf = ConfigParser.ConfigParser()  # 文件读取遍历fileReader
conf.read("conf/ini.txt")  # 设置log的输入文件

class DataCenter:
    def __init__(self):
        self.clientEnable = True
        self.inTest = False
        # 动态窗口参数
        self.client_width = 1000
        self.client_height = 715
        self.logPanel_width = 375
        self.logPanel_height = 715
        self.contentPanel_width = 375
        self.contentPanel_height = 715
        # 静态窗口参数
        self.menuPanel_width = 250
        self.contentTitle_height = 55
        self.contentLine_height = 50
        # 页面背景色
        self.pageBgColor = '#ffffff'
        self.thread_unitTest = None

        self.pyToolsInterval = int(conf.get("pyTools","interval"))
        self.pyToolsProNum = int(conf.get("pyTools","processNum"))
        self.pyToolsVoiceGroupNum_81 = int(conf.get("pyTools","voiceGroupNum_81"))
        self.pyToolsVoiceGroupNum_158 = int(conf.get("pyTools","voiceGroupNum_158"))
        self.pyToolsVoiceGroupNum_184 = int(conf.get("pyTools","voiceGroupNum_184"))
        self.pyToolsProcessNum = int(conf.get("pyTools","processNum"))
        self.pyToolsVoiceLength = int(conf.get("pyTools", "voiceLength"))
        self.tcpToken = None
        self._const = {
            'HTTP':{
                'HOST':'114.55.176.184',
                #'HOST':'114.55.63.81',
                'PORT':80
            },
            'TCP':{
                'HOST': '120.27.201.238',
                'PORT': 8087,
                'PATH':'fn-ws',
            },
            'WS':{
                'CONFIG':{
                    'HOST':'120.55.144.128',#负载均衡服务器：120.55.144.128
                    #'HOST':'120.27.202.5',#负载均衡服务器：120.55.144.128
                    #'HOST':'120.27.201.238',#负载均衡服务器：120.55.144.128
                    #'HOST':'114.55.176.110',#负载均衡服务器：120.55.144.128
                    'PORT':8087,
                    'PATH':'fn-ws'
                },
                'TOKEN': '',
                'cid': None,
                'sid': None,
                'aip': None,
                'aport': None,
                'stat': None
            },
            'RTPWS':{
                'CONFIG':{
                    'HOST':'127.0.0.1',
                    'PORT':8087,
                    'PATH':''
                },
                'cid': None,
                'sid': None,
                'aip': None,
                'aport': None,
                'stat': None
            },
            'TEMPGROUP_TYPE':{
                'singleCall':4,
                'tempGroup':5,
                'boardCast':3
            },
            'CHANNEL_TYPE':{
                'intercom':1,
                'meeting':2,
                'broadcast':3,
                'singleCall':4,
                'tempGroup':5
            },
            'PressureTest':{
                'maxTimeout':30000,
                'softwareQuery':0,
                'groupQuery':0,
                'getGroupMemberNum':0,

                'loginNum':0,
                'groupQueryNum':0,
                'tcpInNum':0,
                'heartbeatNum':0,
                'inChannelNum':0,
                'onlineNumMax':0,
                
                'timeMin_softwareQuery':0,
                'timeMax_softwareQuery':0,
                'timeMin_httpLogin':0,
                'timeMax_httpLogin':0,
                'timeMin_groupQuery': 0,
                'timeMax_groupQuery': 0,
                'timeMin_getGroupMember':0,
                'timeMax_getGroupMember':0,
                'timeMin_tcpIn':0,
                'timeMax_tcpIn':0,
                'timeMin_heart':0,
                'timeMax_heart':0,
                'timeMin_inChannel':0,
                'timeMax_inChannel':0
            },
            'simulationTest':{
                'bakIntercomGroup':0,
                'transmitTime':0
            }
        }
        # 1:对讲；2:会议；3:广播；4:单呼；5:临时组
        self.videoType=[1,2,3,4,5]

        # 网路状态
        self.netstatus = 0

        # 发送Rtp语音包的模式:
        # 1 >>间歇性发包：一个人发包60秒后，休息1.5秒后，随机另外的人进行发包
        # 2 >>连续性发包：一个人发包60秒后，另外一个人接着进行发包
        # 3 >>发送真实的语音包
        # 4 >>发送真实的语言包，带上sequenceNum
        self.sendRtpType = 4

        self.treeListCompare = {'1': u"单元测试",'2': u"接口测试",'3': u"集成测试",'4': u"性能测试",'5': u"安全测试",'6': u"容灾测试",'7':u"终端模拟",'8':u"对讲模拟"}
        self.reportSummary = {'test_name':u'项目名称','test_version':u'测试版本','test_pl':u'测试平台','test_net':u'测试网络','test_sum':u'测试总数','test_success':u'通过总数','test_failed':u'失败总数','test_date':u'测试日期','test_score':u'测试评分'}

        self.testResult = []
        self.reportDetails = []
        self.rtpUserArray = []

    def rtpUserAdd(self, uid, sid, cid, aip, aport):
        if len(self.rtpUserArray)==0:
            newRtpUser = {"uid":str(uid), "sid":str(sid), "cid":str(cid), "aip":str(aip), "aport":str(aport)}
            self.rtpUserArray.append(newRtpUser)
        else:
            statusIn = False
            for user in self.rtpUserArray:
                if (user["uid"]==str(uid)):
                    statusIn = True
                    user["sid"] = sid
                    user["cid"] = cid
                    user["aip"] = aip
                    user["aport"] = aport
            if statusIn == False:
                newRtpUser = {"uid": str(uid), "sid": str(sid), "cid": str(cid), "aip": str(aip), "aport": str(aport)}
                self.rtpUserArray.append(newRtpUser)

    def testReportAppend(self,id,name,method,url,param,expectedResult,actualResult,testResult):
        reportArray = []
        reportArray.append(id)
        reportArray.append(name)
        reportArray.append(method)
        reportArray.append(url)
        reportArray.append(param)
        reportArray.append(expectedResult)
        reportArray.append(actualResult)
        reportArray.append(testResult)
        self.reportDetails.append(reportArray)

    def testResultAppend(self, module, func, destination, precondition, execStep, expectedResult, testResult, problemTypes, priority, version, reporter, agent):
        testArray = []
        testArray.append(module)
        testArray.append(func)
        testArray.append(destination)
        testArray.append(precondition)
        testArray.append(execStep)
        testArray.append(expectedResult)
        testArray.append(testResult)
        testArray.append(problemTypes)
        testArray.append(priority)
        testArray.append(version)
        testArray.append(reporter)
        testArray.append(agent)
        self.testResult.append(testArray)
